<?php
require_once 'duck/DuckInterface.php';
require_once 'adapt/EAdapt.php';
require_once 'duck/DuckGreen.php';
require_once 'duck/DuckRed.php';
require_once 'e/E.php';
require_once 'decker/DuckDecker.php';
require_once 'factory/DuckFactoryInterface.php';
require_once 'factory/DuckFactory.php';
require_once 'factory/CountDuckFactoryInterface.php';

class DuckSimulator {
    protected $ducks;

    public function setDuck(DuckInterface $d)
    {
        $this->ducks[] = $d;
    }

    public function quick()
    {
        foreach ($this->ducks as $duck)
        {
            $duck->quick();
        }
    }

    public function getQuickCount()
    {
        $count = 0;
        foreach ($this->ducks as $duck)
        {
            $count += $duck->getQuick();
        }
        return $count;
    }
}

$countDuckFactory = new CountDuckFactoryInterface();
$simulator  = new DuckSimulator();

$simulator->setDuck($countDuckFactory->createGreenDuck());
$simulator->setDuck($countDuckFactory->createRedDuck());
$e          = new E();
$simulator->setDuck($countDuckFactory->createE());
$simulator->quick();
echo "<br>叫的次数: ";
echo $simulator->getQuickCount();